package com.taotao.manage.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.pojo.EasyUIResult;
import com.taotao.manage.mapper.ContentMapper;
import com.taotao.manage.pojo.Content;

@Service
public class ContentService extends BaseService<Content> {
	
	@Autowired
	private ContentMapper contentMapper;

	/**
	 * 根据条件分页并排序查询
	 * @param categoryId
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public EasyUIResult<Content> queryByPageOrderBy(Long categoryId, Integer pageNum, Integer pageSize) {
		// 分页
		PageHelper.startPage(pageNum, pageSize);
		// 创建example对象
		Example example = new Example(Content.class);
		// 设置查询条件
		example.createCriteria().andEqualTo("categoryId", categoryId);
		// 设置排序规则
		example.setOrderByClause("updated desc");
		// 执行查询
		List<Content> list = this.contentMapper.selectByExample(example);
		// 创建pageInfo对象
		PageInfo<Content> pageInfo = new PageInfo<>(list);
		// 返回分页对象
		return new EasyUIResult<>(pageInfo.getTotal(), pageInfo.getList());
	}

}
